package com.glory.wxelectricitypda.activity;

import android.os.Handler;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.glory.wxelectricitypda.R;
import com.glory.wxelectricitypda.adapter.AddCarrierDataAdapter;
import com.glory.wxelectricitypda.adapter.ItemBomInfoAdapter;
import com.glory.wxelectricitypda.adapter.MLotDataAdapter;
import com.glory.wxelectricitypda.adapter.TOOLDataAdapter;
import com.glory.wxelectricitypda.base.BaseDialogActivity;
import com.glory.wxelectricitypda.bean.EqpEntoty;
import com.glory.wxelectricitypda.bean.EquipmentBean;
import com.glory.wxelectricitypda.bean.LotBean;
import com.glory.wxelectricitypda.bean.MatListEntity;
import com.glory.wxelectricitypda.bean.ResponseBean;
import com.glory.wxelectricitypda.bean.VendertBean;
import com.glory.wxelectricitypda.utils.NetUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_DialogEntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_TextCallback;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralFragmentDialog;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralPop;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_PopUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class NewTrackInActivity extends BaseDialogActivity {


    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.etUser)
    FreeUI_ClearEditText etUser;
    @BindView(R.id.etLotId)
    FreeUI_ClearEditText etLotId;
    @BindView(R.id.etItemCount)
    FreeUI_ClearEditText etItemCount;
    @BindView(R.id.tvStep)
    TextView tvStep;
    @BindView(R.id.tvLotQty)
    TextView tvLotQty;
    @BindView(R.id.tvAttribute1)
    TextView tvAttribute1;
    @BindView(R.id.rvBomList)
    RecyclerView rvBomList;
    @BindView(R.id.tvCarryId)
    TextView tvCarryId;
    @BindView(R.id.rvMaterielModelList)
    RecyclerView rvMaterielModelList;
    @BindView(R.id.etMaterielModel)
    FreeUI_ClearEditText etMaterielModel;
    @BindView(R.id.rvMLOTLIST)
    RecyclerView rvMLOTLIST;
    @BindView(R.id.rvTOOLLIST)
    RecyclerView rvTOOLLIST;
    @BindView(R.id.tvPartName)
    TextView tvPartName;
    @BindView(R.id.llProviderItem)
    LinearLayout llProviderItem;
    @BindView(R.id.llGoodsShelves)
    LinearLayout llGoodsShelves;
    @BindView(R.id.llCheckGoodsShelves)
    LinearLayout llCheckGoodsShelves;
    @BindView(R.id.llTestGoodsShelves)
    LinearLayout llTestGoodsShelves;
    @BindView(R.id.llGrade)
    LinearLayout llGrade;
    @BindView(R.id.llDatecodes)
    LinearLayout llDatecodes;
    @BindView(R.id.tvGoodsShelvesTitle)
    TextView tvGoodsShelvesTitle;
    @BindView(R.id.tvGrade)
    TextView tvGrade;
    @BindView(R.id.tvDatecodes)
    TextView tvDatecodes;
    @BindView(R.id.tvTestGoodsShelves)
    TextView tvTestGoodsShelves;
    @BindView(R.id.etGoodsShelves)
    FreeUI_ClearEditText etGoodsShelves;
    @BindView(R.id.etCheckGoodsShelves)
    FreeUI_ClearEditText etCheckGoodsShelves;
    @BindView(R.id.llChildEqpParent)
    LinearLayout llChildEqpParent;
    @BindView(R.id.llChildEqp)
    LinearLayout llChildEqp;
    @BindView(R.id.ivChildArrow)
    ImageView ivChildArrow;
    @BindView(R.id.etChildEqp)
    FreeUI_ClearEditText etChildEqp;
    @BindView(R.id.tvProvider)
    TextView tvProvider;
    @BindView(R.id.llProviderSelect)
    LinearLayout llProviderSelect;
    @BindView(R.id.ivProviderArrow)
    ImageView ivProviderArrow;
    @BindView(R.id.llMainEqpParent)
    LinearLayout llMainEqpParent;
    @BindView(R.id.llMainEqp)
    LinearLayout llMainEqp;
    @BindView(R.id.etMainEqp)
    FreeUI_ClearEditText etMainEqp;
    @BindView(R.id.ivMainArrow)
    ImageView ivMainArrow;

    private ItemBomInfoAdapter mItemBomInfoAdapter = null;
    private FreeUI_GeneralFragmentDialog addCarryIdDialog;
    private AddCarrierDataAdapter materielModelAdapter;
    private MLotDataAdapter mMLotDataAdapter;
    private TOOLDataAdapter mTOOLDataAdapter;
    private LotBean mLotBean;
    private List<VendertBean> providerList;
    private List<EquipmentBean> mainEqpList, childEqpList;
    private FreeUI_GeneralPop mainEqpPop, childEqpPop;
    private FreeUI_GeneralPop providerPop;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_trackin_new;
    }

    @Override
    protected void initView() {
        freeUI_titleView.setTitle("进站");
        freeUI_titleView.setRightListener("提交", new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (etLotId.getText().toString().equals("")) {
                    showToast("请扫描批次编号", false);
                    return;
                }
                trackIn();
            }
        });

        rvBomList.setLayoutManager(new LinearLayoutManager(this));
        rvBomList.setItemAnimator(new DefaultItemAnimator());
        rvBomList.addItemDecoration(new DividerItemDecoration(this, 1));
        mItemBomInfoAdapter = new ItemBomInfoAdapter(null, true);
        mItemBomInfoAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        mItemBomInfoAdapter.isFirstOnly(true);
        rvBomList.setAdapter(mItemBomInfoAdapter);

        rvMaterielModelList.setLayoutManager(new LinearLayoutManager(this));
        rvMaterielModelList.setItemAnimator(new DefaultItemAnimator());
        rvMaterielModelList.addItemDecoration(new DividerItemDecoration(this, 1));
        materielModelAdapter = new AddCarrierDataAdapter(null, getSupportFragmentManager());
        materielModelAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        materielModelAdapter.isFirstOnly(true);
        rvMaterielModelList.setAdapter(materielModelAdapter);

        rvMLOTLIST.setLayoutManager(new LinearLayoutManager(this));
        rvMLOTLIST.setItemAnimator(new DefaultItemAnimator());
        rvMLOTLIST.addItemDecoration(new DividerItemDecoration(this, 1));
        mMLotDataAdapter = new MLotDataAdapter(null);
        mMLotDataAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        mMLotDataAdapter.isFirstOnly(true);
        rvMLOTLIST.setAdapter(mMLotDataAdapter);

        rvTOOLLIST.setLayoutManager(new LinearLayoutManager(this));
        rvTOOLLIST.setItemAnimator(new DefaultItemAnimator());
        rvTOOLLIST.addItemDecoration(new DividerItemDecoration(this, 1));
        mTOOLDataAdapter = new TOOLDataAdapter(null);
        mTOOLDataAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        mTOOLDataAdapter.isFirstOnly(true);
        rvTOOLLIST.setAdapter(mTOOLDataAdapter);

    }

    private void trackIn() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("EqpID", etMainEqp.getText().toString());
            jsonObject.put("LotID", etLotId.getText().toString());
            jsonObject.put("SUBEQPID", etChildEqp.getText().toString());
            jsonObject.put("CarrierList", materielModelAdapter.getData().toString().replace("[", "").replace("]", "").replace(" ", "").replace(",", ";"));
            jsonObject.put("NumberOfBars", etItemCount.getText().toString());
            final String providerId = tvProvider.getText().toString().trim();
            if (llProviderItem.getVisibility() == View.VISIBLE) {
                jsonObject.put("RESERVED1", providerId.split("-")[0]);
            }
            final String goodsShelves = etGoodsShelves.getText().toString().trim();
            if (llGoodsShelves.getVisibility() == View.VISIBLE) {
                jsonObject.put("RESERVED3", goodsShelves);
            }
            ArrayList<MatListEntity> matListEntities = new ArrayList<>();
            for (LotBean.BomInfoBean datum : mItemBomInfoAdapter.getData()) {
                MatListEntity matListEntity = new MatListEntity();
                matListEntity.setMatLot(datum.getMATERIALLOT());
                matListEntity.setMatCode(datum.getMATERIALNAME());
                matListEntities.add(matListEntity);
            }
            JSONArray jsonArray = new JSONArray(new Gson().toJson(matListEntities));
            jsonObject.put("MLotList", jsonArray);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        NetUtils.requestPostUtils("TrackIn", "TrackIn", jsonObject, this, new FreeUI_DialogEntityCallBack<ResponseBean<LotBean>>(
                new TypeToken<ResponseBean<LotBean>>() {
                }.getType(), getSupportFragmentManager(), this) {
            @Override
            public void onSuccess(Response<ResponseBean<LotBean>> response) {
                if (response.body().isSuccess(getApplicationContext(), true, getSupportFragmentManager())) {
                    showToast("进站成功", true);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            finish();
                        }
                    }, 2000);
                }
            }

            @Override
            public void onError(Response<ResponseBean<LotBean>> response) {
                super.onError(response);
                loadError(response.getException(), "TrackIn");
            }
        });
    }

    @Override
    protected void initData() {
        etLotId.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(final CharSequence s, int start, int before, int count) {
                if (start == 0 && before == 0 && count > 1) {
                    String userName = etUser.getText().toString();
                    if (userName.isEmpty()) {
                        showToast("请输入操作人工号", false);
                        return;
                    }

                    requestUser(userName, new CallBack() {

                        @Override
                        public void success() {


                            mLotBean = null;
                            mainEqpList = null;
                            childEqpList = null;
                            providerList = null;
                            etMainEqp.setText("");
                            mItemBomInfoAdapter.isCreate(true);
                            mItemBomInfoAdapter.notifyDataSetChanged();
                            JSONObject jsonObject = new JSONObject();
                            try {
                                jsonObject.put("LotID", s.toString());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            NetUtils.requestPostUtils("getLotInfo", "GetLotInfo", jsonObject, this, new FreeUI_DialogEntityCallBack<ResponseBean<LotBean>>(
                                    new TypeToken<ResponseBean<LotBean>>() {
                                    }.getType(), getSupportFragmentManager(), this) {
                                @Override
                                public void onSuccess(Response<ResponseBean<LotBean>> response) {
                                    if (response.body().isSuccess(getApplicationContext(), true, getSupportFragmentManager())) {
                                        mLotBean = response.body().getBody();
                                        tvStep.setText(response.body().getBody().getLotInfo().getSTEPDESC());
                                        tvLotQty.setText(String.valueOf(response.body().getBody().getLotInfo().getMAINQTY()));
                                        tvAttribute1.setText(response.body().getBody().getLotInfo().getATTRIBUTE1());
                                        etItemCount.setText(response.body().getBody().getLotInfo().getCOUNTBARS());
                                        tvPartName.setText(response.body().getBody().getLotInfo().getPARTNAME());
                                        tvGrade.setText(response.body().getBody().getGRADES());
                                        tvDatecodes.setText(response.body().getBody().getDATECODES());
                                        mItemBomInfoAdapter.setNewData(response.body().getBody().getBomInfo());

                                        mainEqpList = mLotBean.getEQUIPMENTLIST();
                                        if (mainEqpList.size() > 0) {
                                            llMainEqpParent.setVisibility(View.VISIBLE);
                                        } else {
                                            mItemBomInfoAdapter.isCreate(false);
                                            mItemBomInfoAdapter.notifyDataSetChanged();
                                            llMainEqpParent.setVisibility(View.GONE);
                                        }
                                        childEqpList = mLotBean.getSUBEQUIPMENTLIST();
                                        if (childEqpList.size() > 0) {
                                            llChildEqpParent.setVisibility(View.VISIBLE);
                                        } else {
                                            llChildEqpParent.setVisibility(View.GONE);
                                        }
                                        //工步相关栏位操作
                                        String workStep = mLotBean.getLotInfo().getSTEPNAME();
                                        switch (workStep) {
                                            case "T200":
                                            case "T103":
                                            case "T201":
                                            case "T300":
                                            case "A102":
                                            case "T301":
                                            case "A103":
                                            case "A501":
                                            case "A204":
                                            case "A404":
                                            case "A603":
                                            case "A416":
                                            case "A503":
                                            case "A221":
                                            case "Q100":
                                            case "A612":
                                                llProviderItem.setVisibility(View.GONE);
                                                llGoodsShelves.setVisibility(View.GONE);
                                                llCheckGoodsShelves.setVisibility(View.GONE);
                                                llTestGoodsShelves.setVisibility(View.VISIBLE);
                                                llGrade.setVisibility(View.VISIBLE);
                                                llDatecodes.setVisibility(View.VISIBLE);
                                                tvGoodsShelvesTitle.setText("测试货架号：");
                                                tvGrade.setText(mLotBean.getGRADES());
                                                tvDatecodes.setText(mLotBean.getDATECODES());
                                                tvTestGoodsShelves.setText(mLotBean.getLotInfo().getATTRIBUTE4());
                                                tvCarryId.setText(mLotBean.getLotInfo().getATTRIBUTE3());
                                                break;
                                            case "A308":
                                                llGoodsShelves.setVisibility(View.VISIBLE);
                                                llProviderItem.setVisibility(View.GONE);
                                                llCheckGoodsShelves.setVisibility(View.GONE);
                                                llTestGoodsShelves.setVisibility(View.VISIBLE);
                                                llGrade.setVisibility(View.VISIBLE);
                                                llDatecodes.setVisibility(View.VISIBLE);
                                                tvGoodsShelvesTitle.setText("测试货架号：");
                                                tvGrade.setText(mLotBean.getGRADES());
                                                tvDatecodes.setText(mLotBean.getDATECODES());
                                                tvTestGoodsShelves.setText(mLotBean.getLotInfo().getATTRIBUTE4());
                                                tvCarryId.setText(mLotBean.getLotInfo().getATTRIBUTE3());
                                                break;
                                            case "A401":
                                            case "A402":
                                                llProviderItem.setVisibility(View.GONE);
                                                llGoodsShelves.setVisibility(View.GONE);
                                                llCheckGoodsShelves.setVisibility(View.GONE);
                                                llTestGoodsShelves.setVisibility(View.VISIBLE);
                                                llGrade.setVisibility(View.GONE);
                                                llDatecodes.setVisibility(View.GONE);
                                                tvTestGoodsShelves.setText(mLotBean.getLotInfo().getATTRIBUTE4());
                                                tvGoodsShelvesTitle.setText("货架号：");
                                                tvCarryId.setText("");
                                                break;
                                            case "A500":
                                                llProviderItem.setVisibility(View.VISIBLE);
                                                llGoodsShelves.setVisibility(View.GONE);
                                                llCheckGoodsShelves.setVisibility(View.GONE);
                                                llTestGoodsShelves.setVisibility(View.GONE);
                                                llGrade.setVisibility(View.GONE);
                                                llDatecodes.setVisibility(View.GONE);
                                                providerList = mLotBean.getVENDERLIST();
                                                tvCarryId.setText("");
                                                break;
                                            case "T100":
                                                tvCarryId.setText("");
                                                llProviderItem.setVisibility(View.GONE);
                                                llGoodsShelves.setVisibility(View.VISIBLE);
                                                llTestGoodsShelves.setVisibility(View.GONE);
                                                llGrade.setVisibility(View.GONE);
                                                llDatecodes.setVisibility(View.GONE);
                                                etGoodsShelves.setText(mLotBean.getLotInfo().getATTRIBUTE5());
                                                if (mLotBean.getLotInfo().getATTRIBUTE5().length() > 0) {
                                                    llCheckGoodsShelves.setVisibility(View.VISIBLE);
                                                    etCheckGoodsShelves.requestFocus();
                                                    etCheckGoodsShelves.addTextChangedListener(new TextWatcher() {
                                                        @Override
                                                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                                                        }

                                                        @Override
                                                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                                                            if (start == 0 && before == 0 && count > 1) {
                                                                trackIn();
                                                            }
                                                        }

                                                        @Override
                                                        public void afterTextChanged(Editable s) {

                                                        }
                                                    });
                                                }
                                                break;
                                            default:
                                                tvCarryId.setText("");
                                                llProviderItem.setVisibility(View.GONE);
                                                llGoodsShelves.setVisibility(View.GONE);
                                                llCheckGoodsShelves.setVisibility(View.GONE);
                                                llTestGoodsShelves.setVisibility(View.GONE);
                                                llGrade.setVisibility(View.GONE);
                                                llDatecodes.setVisibility(View.GONE);
                                                break;
                                        }
                                    }
                                }
                                @Override
                                public void onError(Response<ResponseBean<LotBean>> response) {
                                    super.onError(response);
                                    loadError(response.getException(), "GetLotInfo");
                                }
                            });
                        }
                        @Override
                        public void fail() {
                            showToast("操作人工号验证失败，请重新输入", false);
                        }
                        @Override
                        public void error() {
                            showToast("连接不到服务器，请重试", false);
                        }
                    });
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        initEdit(etMaterielModel, s -> {
            if (materielModelAdapter.getData().contains(s)) {
                showToast("当前载具已添加到载具列表中", false);
                return;
            }
            materielModelAdapter.getData().add(s);
            materielModelAdapter.notifyDataSetChanged();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    etMaterielModel.setText("");
                    etMaterielModel.requestFocus();
                }
            }, 500);
        });

        initEdit(etMainEqp, s -> {
            mMLotDataAdapter.setNewData(null);
            mTOOLDataAdapter.setNewData(null);
            for (LotBean.BomInfoBean datum : mItemBomInfoAdapter.getData()) {
                datum.setMATERIALLOT("");
            }
            mItemBomInfoAdapter.notifyDataSetChanged();
            if (mLotBean == null) {
                showToast("请扫描批次号", false);
                return;
            }
            getEqpKitting(s,"TOOL");
            getEqpKitting(s,"MLOT");
        });

    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return new FreeUI_AddViewEntity(getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY), llMain);
    }

    @OnClick({R.id.rlCarryId, R.id.llChildEqp, R.id.llProviderSelect, R.id.llMainEqp})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rlCarryId:
                addCarryIdDialog = FreeApi_DialogUtils.getScanDialog(this, "请扫描载具编号", new FreeUI_TextCallback() {
                    @Override
                    public void onSuccess(String s) {
                        String carryIds = tvCarryId.getText().toString().trim();
                        boolean isSame = false;
                        if (carryIds.length() == 0) {
                            tvCarryId.setText(s);
                        } else {
                            if (carryIds.contains(";")) {
                                String[] array = carryIds.split(";");
                                for (String str : array) {
                                    if (str.equals(s)) {
                                        isSame = true;
                                    }
                                }
                            } else {
                                if (carryIds.equals(s)) {
                                    isSame = true;
                                }
                            }
                            if (isSame) {
                                showToast("载具编号不能重复", false);
                            } else {
                                StringBuffer stringBuffer = new StringBuffer();
                                stringBuffer.append(carryIds);
                                stringBuffer.append(";");
                                stringBuffer.append(s);
                                tvCarryId.setText(stringBuffer.toString());
                            }
                        }
                        addCarryIdDialog.dismiss();
                    }
                });
                addCarryIdDialog.show(getSupportFragmentManager(), "addCarryIdDialog");
                break;
            case R.id.llChildEqp:
                if (childEqpList == null) {
                    showToast("还未获取到子设备列表,请重新扫描批次", false);
                    return;
                }
                if (childEqpPop == null) {
                    List<String> list = new ArrayList<>();
                    for (EquipmentBean equipmentBean : childEqpList) {
                        list.add(equipmentBean.getEQUIPMENTID());
                    }
                    childEqpPop = FreeApi_PopUtils.getNormalPop(this, llChildEqp.getWidth(), list, ivChildArrow, new FreeUI_TextCallback() {
                        @Override
                        public void onSuccess(String s) {
                            etChildEqp.setText(s);
                        }
                    });
                }
                showTypePop(childEqpPop, ivChildArrow, llChildEqp);
                break;
            case R.id.llProviderSelect:
                if (providerList == null) {
                    showToast("还未获取到供应商列表,请重新扫描批次", false);
                    return;
                }
                if (providerPop == null) {
                    List<String> list = new ArrayList<>();
                    for (VendertBean vendertBean : providerList) {
                        list.add(vendertBean.getCUSTOMERCODE() + "-" + vendertBean.getDESCRIPTION());
                    }
                    providerPop = FreeApi_PopUtils.getNormalPop(this, llProviderSelect.getWidth(), list, ivProviderArrow, new FreeUI_TextCallback() {
                        @Override
                        public void onSuccess(String s) {
                            tvProvider.setText(s);
                        }
                    });
                }
                showTypePop(providerPop, ivProviderArrow, llProviderSelect);
                break;
            case R.id.llMainEqp:
                if (mainEqpList == null) {
                    showToast("还未获取到主设备列表,请重新扫描批次", false);
                    return;
                }
                if (mainEqpPop == null) {
                    List<String> list = new ArrayList<>();
                    for (EquipmentBean equipmentBean : mainEqpList) {
                        list.add(equipmentBean.getEQUIPMENTID());
                    }
                    mainEqpPop = FreeApi_PopUtils.getNormalPop(this, llMainEqp.getWidth(), list, ivMainArrow, new FreeUI_TextCallback() {
                        @Override
                        public void onSuccess(String s) {
                            etMainEqp.setText(s);
                            mMLotDataAdapter.setNewData(null);
                            mTOOLDataAdapter.setNewData(null);
                            for (LotBean.BomInfoBean datum : mItemBomInfoAdapter.getData()) {
                                datum.setMATERIALLOT("");
                            }
                            mItemBomInfoAdapter.notifyDataSetChanged();
                            if (mLotBean == null) {
                                showToast("请扫描批次号", false);
                                return;
                            }
                            getEqpKitting(s,"MLOT");
                            getEqpKitting(s,"TOOL");
                        }
                    });
                }
                showTypePop(mainEqpPop, ivMainArrow, llMainEqp);
                break;
        }
    }

    private void getEqpKitting(String eqpID,String chargType) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("EqpID", eqpID);
            jsonObject.put("ChargType", chargType);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        NetUtils.requestPostUtils("getEqpKitting", "GetEqpKitting", jsonObject, this, new FreeUI_DialogEntityCallBack<ResponseBean<EqpEntoty>>(
                new TypeToken<ResponseBean<EqpEntoty>>() {
                }.getType(), getSupportFragmentManager(), this) {
            @Override
            public void onSuccess(Response<ResponseBean<EqpEntoty>> response) {
                if (response.body().isSuccess(getApplicationContext(), true, getSupportFragmentManager())) {

                    if (chargType.equals("MLOT")){
                        mMLotDataAdapter.setNewData(response.body().getBody().getMKitting().getMLOTLIST());
                        for (LotBean.BomInfoBean bomInfo : mItemBomInfoAdapter.getData()) {
                            for (EqpEntoty.MaterierlBean materierlBean : response.body().getBody().getMKitting().getMLOTLIST()) {
                                if (materierlBean.getMATERIALTYPE().equals(bomInfo.getMATERIALTYPE())) {
                                    bomInfo.setMATERIALLOT(materierlBean.getMLOTID());
                                }
                            }
                        }
                    }else {
                        mTOOLDataAdapter.setNewData(response.body().getBody().getMKitting().getTOOLLIST());
                        for (LotBean.BomInfoBean bomInfo : mItemBomInfoAdapter.getData()) {
                            for (EqpEntoty.FixtureBean materierlBean : response.body().getBody().getMKitting().getTOOLLIST()) {
                                if (materierlBean.getMATERIALTYPE().equals(bomInfo.getMATERIALTYPE())) {
                                    bomInfo.setMATERIALLOT(materierlBean.getMLOTID());
                                }
                            }
                        }
                    }

                    mItemBomInfoAdapter.isCreate(false);
                    mItemBomInfoAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onError(Response<ResponseBean<EqpEntoty>> response) {
                super.onError(response);
                loadError(response.getException(), "GetEqpKitting");
            }
        });
    }

    private void showTypePop(FreeUI_GeneralPop pop, View view, View showForView) {
        if (pop.isShowing()) {
            pop.dismiss();
        } else {
            FreeApi_PopUtils.setArrowShow(view);
            pop.showAsDropDown(showForView, 0, 0);
        }
    }

}
